package com.film.controller.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.movie.MovieCommentServiceImpl;
import com.film.service.movie.MovieCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@RestController
public class MovieCommentController {
    @Autowired
    private MovieCommentServiceImpl movieCommentService;

    @PostMapping("/movie/comment/{movieId}/{comment}/{commentatorId}/{token}")
    public JSONObject comment(@PathVariable Integer movieId , @PathVariable String comment, @PathVariable Integer commentatorId, @PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return movieCommentService.comment(movieId, comment, commentatorId);
        }
    }
}
